package com.example.smartall.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartall.R;
import com.example.smartall.api.Api;
import com.example.smartall.api.ApiConfig;
import com.example.smartall.api.NetCallBack;
import com.example.smartall.entity.ParkingDetailsBean;
import com.example.smartall.ui.base.BaseActivity;
import com.google.gson.Gson;

/**
  * @Author:         abbas
  * @CreateDate:     2022/1/30
  * @Description:    停车场详情页面 没什么好看的
  */
public class CarParkingDetailsActivity extends BaseActivity {

    private int parkId;

    private ImageView imBack;
    private TextView tvTitle;
    private ImageView im;
    private TextView tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_parking_detials);

        parkId = getIntent().getIntExtra("id",-1);
        init();
        initEvent();
        getParkDetails();
    }

    @Override
    public void init() {
        imBack = (ImageView) findViewById(R.id.im_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        im = (ImageView) findViewById(R.id.im);
        tvContent = (TextView) findViewById(R.id.tv_content);

        tvTitle.setText("停车场详情");
    }

    @Override
    public void initEvent() {
        imBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CarParkingDetailsActivity.this.finish();
            }
        });
    }

    private void getParkDetails(){
        if (parkId < 0){
            showToast("数据错误");
            return;
        }
        Api.config(ApiConfig.PARKING_DETAILS,null).getRequest(new NetCallBack() {
            @Override
            public void onSuccess(String res) {
                ParkingDetailsBean detailsBean = new Gson().fromJson(res,ParkingDetailsBean.class);
                if (detailsBean != null && detailsBean.getCode() ==200){
                    ParkingDetailsBean.DataBean dataBean = detailsBean.getData();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(CarParkingDetailsActivity.this)
                                    .load(ApiConfig.BASE_URL + dataBean.getImgUrl())
                                    .into(im);
                            tvContent.setText(dataBean.getParkName() + "\n"+
                                    "地址："+dataBean.getAddress()+"\n"+
                                    "距离："+dataBean.getDistance()+"\n"+
                                    "今日是否开放："+(dataBean.getOpen().equals("Y")?"是":"否")+"\n"+
                                    "总停车位："+dataBean.getAllPark()+"\n"+
                                    "停车费："+dataBean.getRates()+"小时/元"+"\n"+
                                    "剩余停车位："+dataBean.getVacancy()+"\n"+
                                    "收费参考：停车费每小时"+dataBean.getRates()+"元,最高"+dataBean.getPriceCaps()+"/天");
                        }
                    });
                }
            }

            @Override
            public void onFailure(Exception e) {

            }
        },parkId+"");
    }
}